#ifndef MESSAGE_ENCDOE_BUFFER_H_
#define MESSAGE_ENCDOE_BUFFER_H_

#include "udp_fec_packet.h"

class MessageEncodeBuffer
{
public:
    MessageEncodeBuffer(int block_size, int parity_num);
    FecPacketList     appendAndTryEncode(const char* buf, int len);
    void        clear();
    bool        empty() { return packets_.empty(); }
    FecPacketList     forceEncode();

private:
    FecPacketList     makeMessage(const char* data, int len);
    FecPacketList     encode();
    FecPacketList     fillFecInfo();
    bool        ready();

    int         getBlockSize();
    int         getParityNum();
    int         getTotalSize();
    int         getNextBlockId();
    int         getNextMsgId();

private:
    //can not reset
    int next_block_id;
    int fec_block_size_;
    int fec_parity_num_;

    //can reset
    int next_msg_id;
    FecPacketList packets_;
    FecPacketList paritys_;
};
typedef std::shared_ptr<MessageEncodeBuffer> SpMessageEncodeBuffer;

#endif//MESSAGE_ENCDOE_BUFFER_H_
